package com.atguigu02.reference;

import org.junit.Test;

import java.util.function.Function;
import java.util.function.Supplier;

public class ConstructorRefTest {

    @Test
    public void t1(){
        Supplier<Employee> s1=new Supplier<Employee>() {
            @Override
            public Employee get() {
                return new Employee();
            }
        };
        System.out.println(s1.get());

        Supplier<Employee> s2=Employee::new;
        System.out.println(s2.get());

    }
    @Test
    public void t2(){
        Function<Integer,Employee> f1=new Function<Integer, Employee>() {
            @Override
            public Employee apply(Integer id) {
                return new Employee(id);
            }
        };
        System.out.println(f1.apply(12));
        //构造器调用
        Function<Integer,Employee> f2=Employee::new;
        System.out.println(f2.apply(1001));
    }

//数组引用
//Function中的Rapply(T t)
@Test
    public void test4(){
//1.
        Function<Integer ,Employee[]> func1 = new Function<Integer,Employee[]>() {
            public Employee[] apply(Integer length) {
                return new Employee[length];
            }
        };
        System.out.println(func1.apply(10).length);
//2.
        Function<Integer ,Employee[]> func2 = Employee[] :: new;
        System.out.println(func2.apply(20).length);
    }

}
